package com.qlk.odcinterface.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.odcinterface.domain.PmsCouponItem;
import com.qlk.odcinterface.domain.query.PmsCouponItemQuery;
import com.qlk.odcinterface.dao.PmsCouponItemDao;
import com.qlk.odcinterface.manager.PmsCouponItemManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * PmsCouponItemManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 14:11:36
 * 
 */
@Component
public class PmsCouponItemManagerImpl extends BaseManager implements PmsCouponItemManager {
	
    @Autowired
    private PmsCouponItemDao pmsCouponItemDao;

    /**
     * {@inheritDoc}
     */
    public boolean insert(final List<PmsCouponItem> pmsCouponItemList) {
        boolean resultFlag = false;
        if (null != pmsCouponItemList && pmsCouponItemList.size() > 0) {
            for (PmsCouponItem pmsCouponItem : pmsCouponItemList) {
                resultFlag = pmsCouponItemDao.insert(pmsCouponItem);
                if (!resultFlag) {
                    throw new RuntimeException("批量新增表信息异常");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean insert(PmsCouponItem pmsCouponItem) {
        return pmsCouponItemDao.insert(pmsCouponItem);
    }

    /**
     * {@inheritDoc}
     */
    public boolean update(final PmsCouponItem pmsCouponItem) {
        return pmsCouponItemDao.update(pmsCouponItem);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsCouponItem> queryPmsCouponItemList(PmsCouponItemQuery queryBean) {
        return pmsCouponItemDao.queryPmsCouponItemList(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsCouponItem> queryPmsCouponItemListWithPage(PmsCouponItemQuery queryBean,
            PageUtil pageUtil) {
        if (null == queryBean) {
            queryBean = new PmsCouponItemQuery();
        }

        // 查询总数
        int totalItem = queryPmsCouponItemCount(queryBean);

        if (pageUtil == null) {
            pageUtil = new PageUtil();
        }
        pageUtil.setTotalRow(totalItem);
        pageUtil.init();
        
        if (totalItem > 0) {
            queryBean.setPageIndex(pageUtil.getCurPage());
            queryBean.setPageSize(pageUtil.getPageSize());
            // 调用Dao翻页方法
            return pmsCouponItemDao.queryPmsCouponItemListWithPage(queryBean);
        }
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public int queryPmsCouponItemCount(PmsCouponItemQuery queryBean) {
        return pmsCouponItemDao.queryPmsCouponItemCount(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(PmsCouponItem pmsCouponItem) {
        return pmsCouponItemDao.delete(pmsCouponItem);
    }

    /**
     * {@inheritDoc}
     */
    public PmsCouponItem getPmsCouponItemById(Long id) {
        return pmsCouponItemDao.getPmsCouponItemById(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(final PmsCouponItem[] pmsCouponItems) {
        boolean resultFlag = false;
        if (null != pmsCouponItems && pmsCouponItems.length > 0) {
            for (int i = 0; i < pmsCouponItems.length; i++) {
                resultFlag = delete(pmsCouponItems[i]);
                if (!resultFlag) {
                    throw new RuntimeException("批量删除表信息异常!");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean exist(PmsCouponItem pmsCouponItem) {
        return pmsCouponItemDao.exist(pmsCouponItem);
    }
}
